package problem2;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main {

	public static void main(String[] args) {
		testCopy();
	}

	public static <T extends Fruit> void copyAll(Collection<? extends T> in, Collection<? super T> out) {
		if (in!=null & out!=null) {
			out.addAll(in);
		}
	}
	
	public static void testCopy () {
		System.out.println("Test fruits!!");
		List<Fruit> fr = null;
		List<Apple> app = null;
		List<Orange> or = null;
		List<RedApple> rapp = null;
		//List<Melon> mel = null;    We don't use it
		
		copyAll(or,fr);
		copyAll(rapp,fr);
		copyAll(rapp,app);
		copyAll(rapp,rapp);
		//copyAll(fr,or);   It doesn't work
		//copyAll(mel,fr);  It doesn't work too
		
		List<Fruit> fr2 = new ArrayList<Fruit>() {
			
			private static final long serialVersionUID = 1L;

			{
				add(new Fruit());
				add(new Apple());
				add(new RedApple());
				add(new Orange());
			}
		};
		List<Fruit> fr3 = new ArrayList<Fruit>();
		copyAll(fr2,fr3);
		System.out.println(fr3);
		
	}
}
